﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BuffPrefixV2
{
    public class PrefixPlayer
    {
        public string Name { get; set; }
        public int CurrentPrefixID { get; set; }
        public List<int> PrefixPossessions { get; set; }
        public PrefixPlayer(string name,int currentPrefixID,List<int> prefixes)
        {
            Name = name;
            CurrentPrefixID = currentPrefixID;
            PrefixPossessions = prefixes;
            
        }
        public string IntoString() { 
            return string.Join(",", PrefixPossessions);
        }
        /// <summary>
        /// 判断玩家是否拥有此称号
        /// </summary>
        /// <param name="prefixID"></param>
        /// <returns></returns>
        public bool IsOwned(int prefixID) {
            if (PrefixPossessions.Contains(prefixID))
            {
                return true;
            }
            else {
                return false;
            }
        }
        public bool AddPrefix(int prefixID) {
            if (IsOwned(prefixID)==false)
            {
                PrefixPossessions.Add(prefixID);
                DBManager.UpdatePrefixPlayer(this);
                return true;
            }
            else {
                return false;
            }
        }
        public bool DelPrefix(int prefixID)
        {
            if (IsOwned(prefixID)==true)
            {
                PrefixPossessions.Remove(prefixID);
                DBManager.UpdatePrefixPlayer(this);
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
